﻿using System;
using System.IO;
using System.Text;

namespace T4.Test.Extentions
{
	internal static class FileExtention
	{
		private static readonly Encoding DefaultEncoding = Encoding.UTF8;
/*		internal static bool IsEqual(this FileInfo fi, string str, Encoding encoding = null)
		{
			if (str == null)
				throw new NullReferenceException("string is null");

			return str.RemoveSpecialCharacters() == Context(fi, encoding, true);
		}*/

		internal static string Context(this FileInfo fi, Encoding encoding = null, bool trimSpaceCharacter = false)
		{
			if (fi == null)
				throw new NullReferenceException("FileInfo is null");

			if (!fi.Exists)
				throw new FileNotFoundException(fi.FullName);

			using (TextReader tr = new StreamReader(fi.FullName, encoding ?? DefaultEncoding))
				return trimSpaceCharacter ? tr.ReadToEnd().RemoveSpecialCharacters() : tr.ReadToEnd();

		}
	}
}
